<template>
  <back-btn></back-btn>
  <div id="app">
    <h2>计数器：{{ count }}</h2>
    <h3>计数器-计算属性: {{ dbCount }}</h3>

    <p ref="decs"></p>
  </div>
</template>

<script>
import { ref, watch, defineComponent } from "vue";
import { useCounter } from "../hooks/useCounter.ts";

export default defineComponent({
  setup() {
    /* 计数器 */
    const { count, dbCount } = useCounter();

    /* 消息 */
    const msg = ref("消息");

    /* 使用元素引用 */
    const decs = ref(null);

    /* 侦听器 */
    watch(count, (newV, oldV) => {
      const p = decs.value;
      p.textContent = `计数器变化 ${oldV} 到 ${newV}`;
    });

    return {
      count,
      dbCount,
      msg,
      decs,
    };
  },
});
</script>

<style lang="scss" scoped></style>
